﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ESAM_Assignment_3
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Eric
            Response.CacheControl = "no-cache";
            if (!(bool)Session[Common.ESAM_LOGIN])
            {
                Response.Redirect("Default.aspx");
            }
        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            //eric
            //string username = Request.QueryString["Username"];
            string username = Session[Common.ESAM_USERNAME].ToString();

            string CurrentPassword = tbxCurrentPassword.Text;
            string NewPassword = tbxNewPassword.Text;

            bool status = UserClass.ChangePassword(username, CurrentPassword, NewPassword);

            if (status)
            {
                lblStatus.Text = "Success. You new password has been saved. Please use the new password at your next logon.";
                lblStatus.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblStatus.Text = "Error! Your new password cannot be saved. Incorrect current password? Please try again.";
                lblStatus.ForeColor = System.Drawing.Color.Red;
            }

            //Reset the textboxes
            tbxCurrentPassword.Text = "";
            tbxNewPassword.Text = "";
            tbxRetypePassword.Text = "";
        }
    }
}